/* 
 * cms，一个基于J2EE架构内容管理系统
 * Copyright © GrayRabbit Co., Ltd. All rights reserved.
 * Department:运营department
 * 更多信息请访问：
 * http://code.google.com/p/gray-rabbit-cms/
 */
package org.grayrabbit.cms.util;

import org.apache.commons.lang.StringUtils;
import org.grayrabbit.cms.component.AbstractComponent;
import org.grayrabbit.cms.component.AssociationDoc;
import org.grayrabbit.cms.component.Cateframe;
import org.grayrabbit.cms.component.Crumbs;
import org.grayrabbit.cms.component.Lefttree;
import org.grayrabbit.cms.component.Rollannounce;
import org.grayrabbit.cms.component.Rotate;
import org.grayrabbit.cms.component.SiteCatNav;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * <b>UploadUtil</b>上传组件：
 * 

 * @version 1.0,创建时间: 2011-05-16 15:55:12
 */
public class ComponentUtil {
	private static Logger LOG = LoggerFactory.getLogger(ComponentUtil.class);
	
	//组件类别常量   进行扩展
	public static final String TYPE_ROLL_ANNOUNCE="rollannounce";
	public static final String TYPE_ROTATE="rotate";
	public static final String TYPE_ASSOCIATION="association";
	public static final String TYPE_ASSOCIATION_DOC="associationdoc";
	public static final String TYPE_PAGINATION = "pagination";
	public static final String TYPE_SITECATNAV = "sitecatnav";
	public static final String TYPE_SITE_CAT_NAV = "site_cat_nav";
	public static final String TYPE_CATEFRAME = "cateFrame";
	public static final String TYPE_CRUMBS = "crumbs";
	public static final String TYPE_LEFTTREE = "leftTree";
	
	/** 加载参数   依据组件类别进行扩展
	 * @param component
	 * @param componentType
	 * @param parameters
	 * @return
	 */
	public static String componentLoadParameters(String component,
			String componentType, String parameters) {
		if(StringUtils.isBlank(parameters)) return component;
		if(StringUtils.isBlank(component)) return null;
		if(StringUtils.isBlank(componentType)) return null;	
		AbstractComponent absc = null; 
		if(TYPE_ROLL_ANNOUNCE.equalsIgnoreCase(componentType)){
			absc = new Rollannounce();
			component = absc.loadComponentInfo(component,parameters);
		}else if(TYPE_ROTATE.equalsIgnoreCase(componentType)){
			absc = new Rotate();
			component = absc.loadComponentInfo(component, parameters);
		}else if(TYPE_ASSOCIATION.equalsIgnoreCase(componentType)) {
			absc = new AssociationDoc();
			component = absc.loadComponentInfo(component, parameters);
		}else if(TYPE_SITE_CAT_NAV.equalsIgnoreCase(componentType)) {
			absc = new SiteCatNav();
			component = absc.loadComponentInfo(component, parameters);
		}else if(TYPE_CATEFRAME.equalsIgnoreCase(componentType)) {
			absc = new Cateframe();
			component = absc.loadComponentInfo(component, parameters);
		}else if(TYPE_CRUMBS.equalsIgnoreCase(componentType)) {
			absc = new Crumbs();
			component = absc.loadComponentInfo(component, parameters);
		}else if(TYPE_LEFTTREE.equalsIgnoreCase(componentType)){
			absc = new Lefttree();
			component = absc.loadComponentInfo(component, parameters);
		}
		LOG.info(parameters); 
		LOG.info(component); 
		return component;
	}
	 
}
